package com.discuz.spider.jpkoo;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;

import com.discuz.post.HttpUtils;

public class Utils {
	
	//bmp,,tiff,,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw
	public static String checkImageName(String p){
		if(p.endsWith("jpg") || p.endsWith("JPG")) return"jpg";
		else if(p.endsWith("gif") || p.endsWith("GIF")) return"gif";
		else if(p.endsWith("bmp") || p.endsWith("BMP")) return"bmp";
		else if(p.endsWith("jpeg") || p.endsWith("JPEG")) return"jpeg";
		return ".jpg";
	} 
	
	
	  private  static String [] reply={
		  "我是忠实粉丝。。",
		  "谢谢楼主的分享",
		  "真的够促性了，慢好，哈哈",
		  "看到黑丝就硬了",
		  "感谢分享 楼主辛苦了",
		  "拍得好,谢谢楼主的分享",
		  "楼主好艳福啊~这个情景不是那么容易见得·",
		  "支持支持支持支持支持支持支持支持支持支持",
		  "支持楼主哈，楼主继续加油咯",
		  "感谢楼主的分享，支持原创，新手敬上",
		  "这丝袜太性感了 很诱惑啊",
		  "先顶后看养成好习惯，楼主辛苦了！",
		  "太有个性了，值得欣赏",
		  "请选择您此刻的心情图片并写下今天最想说的话",
		  "我好喜欢啊，好性感啊，喜欢",
		  "好惹火的身材啊 很霸道 我喜欢",
		  "谢谢楼主分享这么给力",
		  "这样也可以啊性感给力不 来点给力的吧",
		  "太风骚了，保养得不错。太开放了",
		  "特写都有了，极品"};
	
	  public static String randomReply(){
		  
		  return reply[generaterRM(0,19)];
	  }
	  
	  public static void main(String[] args) throws IOException {
		  FileUtils.writeStringToFile(new File("/Users/only/share/jpkoo/2/1.txt"), "");
	        File f = new File("/Users/only/share/jpkoo/2/2.jpg");
	        if(!f.exists()){
	        	f.createNewFile();
	        }
	    }
	  
	  
	  
	    public static int generaterRM(int min,int max){
	    	 Random random = new Random();

		        int s = random.nextInt(max)%(max-min+1) + min;
		        return s;
	    }
	    
	    public static byte [] download(String url) throws IOException, Exception{
	    	byte data [] = null;
	    	HttpGet httpGet = new HttpGet(url); 
	    	HttpResponse response = HttpUtils.get().execute(httpGet) ;
	    	if(HttpStatus.SC_OK==response.getStatusLine().getStatusCode()){ 
	    		 HttpEntity entity = response.getEntity(); 
	    		 if(entity!=null){
	    			 if(entity.isStreaming()){
	    				InputStream in = entity.getContent();
	    				data = IOUtils.toByteArray(in);
	    			 }
	    		 }
	    		 EntityUtils.consume(entity);
	    	}
	    	
	    	return data;
	    }

}
